<template>
	<view>
		<view class="" style="background-color: #fff;">
			<view class="" style="margin-top: 20upx;">
				<view class="" style="height: 100upx;line-height: 100upx; width: 100%;margin-left: 150upx;font-weight: 550;font-size: 35upx;">
					挂卖昵称: <text style="margin-left: 30upx;">{{buy.nick_name}}</text>
				</view>
				<view class="" style="height: 100upx;line-height: 100upx;width: 100%;margin-left: 150upx;font-weight: 550;font-size: 35upx;">
					剩余数量: <text style="margin-left: 110upx;">{{snum}}</text>
				</view>
				<!-- <view class="" style="height: 100upx;line-height: 100upx;width: 100%;margin-left: 150upx;font-weight: 550;font-size: 35upx;">
					总数量 : {{znum}}
				</view> -->
				<view class="" style="display: flex; height: 100upx;line-height: 100upx;width: 100%;margin-left: 150upx;font-weight: 550;font-size: 35upx;">
					<view class="" style=" width: 20%;height: 100upx;line-height: 100upx;font-size: 35upx;">
						购买数量: 
					</view>
					<input type="text" v-model="num" style="text-align: center; margin-left: 50upx; width: 20%;height: 80upx;line-height: 80upx;box-shadow: 2upx 2upx 10upx #CCCCCC;" />
				</view>
				
			</view>
		</view>
		<button @click="getbuy" type="default" style="width: 90%;margin-left: 5%;background-color: #FE7273;margin-top: 30upx;color: #fff;font-weight: 550;">立即购买</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			 buy:'',
			 znum:'',
			 price:'',
			 snum:'',
			 openid:'',
			 num:'',
			};
		},
		onLoad:function(){
			uni.getStorage({
			    key: 'buy',
			    success: (res)=> {
						console.log(res)
			       this.buy = res.data
						 this.znum = this.buy.znum
						 this.price = this.buy.price
						 this.id = this.buy.id
			    }
			});
			uni.getStorage({
			    key: 'openid',
			    success: (res)=> {
			       this.openid = res.data
						 // console.log(this.openid)
						 this.getdata()
			    }
			});
		},
		methods:{
			getdata() {
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.tzz_exchange.buy&app=1',
					method: 'POST',
					data: {
						'openid':this.openid,
						'id' : this.id,
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						console.log(res)
						this.snum = res.data.snum
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getbuy() {
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.tzz_exchange.buy_submit&app=1',
					method: 'POST',
					data: {
						'openid':this.openid,
						'num' : this.num,
						'id' : this.id,
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						console.log(res)
						uni.showToast({
							title:res.data.result.message,
							icon:'none'
						})
						setTimeout(()=> {
							uni.navigateTo({
								url:'buy1'
							})
						}, 1000);
						
					},
					fail: () => {},
					complete: () => {}
				});
			},
		
		},
	}
</script>

<style>
</style>
